package com.zjuh.taofood.biz.bo;

import java.util.List;

import wint.lang.convert.ConvertUtil;
import wint.lang.utils.CollectionUtil;

import com.taobao.api.domain.ItemCat;
import com.taobao.api.domain.TaobaokeItem;
import com.zjuh.taofood.biz.domain.CategoryDO;
import com.zjuh.taofood.biz.domain.TopicItemDO;

public class TaokeUtil {

	public static TopicItemDO toTopicItem(TaobaokeItem taobaokeItem) {
		TopicItemDO ret = new TopicItemDO();
		ret.setItemId(taobaokeItem.getNumIid());
		ret.setClickUrl(taobaokeItem.getClickUrl());
		ret.setCommission(ConvertUtil.toDouble(taobaokeItem.getCommission(), 0.0));
		ret.setCommissionRate(ConvertUtil.toDouble(taobaokeItem.getCommissionRate(), 0.0));
		ret.setItemDetailUrl(taobaokeItem.getClickUrl());
		ret.setItemTitle(taobaokeItem.getTitle());
		ret.setItemPicUrl(taobaokeItem.getPicUrl());
		ret.setPrice(ConvertUtil.toDouble(taobaokeItem.getPrice(), 0.0));
		ret.setSellerCreditScore(taobaokeItem.getSellerCreditScore());
		ret.setSellerNick(taobaokeItem.getNick());
		ret.setVolume(taobaokeItem.getVolume());
		return ret;
	}
	
	public static List<TopicItemDO> toTopicItems(List<TaobaokeItem> taobaokeItems) {
		List<TopicItemDO> ret = CollectionUtil.newArrayList();
		if (taobaokeItems == null) {
			return ret;
		}
		for (TaobaokeItem taobaokeItem : taobaokeItems) {
			ret.add(toTopicItem(taobaokeItem));
		}
		return ret;
	}
	
	public static CategoryDO toCategory(ItemCat itemCat) {
		CategoryDO ret = new CategoryDO();
		ret.setCid(itemCat.getCid());
		ret.setName(itemCat.getName());
		ret.setParentCid(itemCat.getParentCid());
		return ret;
	}
	
}
